<template>
  <div class="row">
    <div class="col">
      <span class="materialsDetails-title">{{ basicData.instanceNumber }}</span>
      <ul class="materialsDetails-meta">
        <li class="materialsDetails-meta-item">{{ basicData.name }}</li>
        <li class="materialsDetails-meta-item">{{ basicData.createBy }}</li>
        <li class="materialsDetails-meta-item">{{ basicData.createTime }}</li>
      </ul>
    </div>
    <div class="col-auto">
      <div class="row justify-content-end align-items-center">
        <div class="col-auto input-suffix">
          <label class="mr-3">状态</label>
          <el-select v-model="statusVal" style="width:128px;" @change="statusChange">
            <el-option
              v-for="(item, k) in options"
              :key="k"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="col-auto input-suffix">
          <label class="mb-0">发布日期：</label>
          <span class="">{{ basicData.publishTime }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getViewObjectInstanceByList
} from '@/api/frontPage/document/index'
export default {
  name: 'BasicInfo',
  props: {
    id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      statusVal: '2',
      options: [
        { label: '2.0', value: '2' },
        { label: '1.0', value: '1' }
      ],
      basicData: {
        instanceNumber: '', // 编号
        name: '', // 类型
        createBy: '', // 创建人
        createTime: '', // 创建时间
        publishTime: '' // 发布日期
      }
    }
  },
  created() {
    this.getBasicInfo()
  },
  methods: {
    statusChange() {
      this.$emit('statusChange', this.statusVal)
    },
    getBasicInfo() {
      getViewObjectInstanceByList(this.id)
        .then(res => {
          const records = res.result
          let basicData = {}
          const name = _ => records.baseObjects ? records.baseObjects.name : ''
          if (records !== null) {
            basicData = {
              instanceNumber: records.instanceNumber, // 编号
              name: name(), // 类型
              createBy: records.createBy, // 创建人
              createTime: records.createTime, // 创建时间
              publishTime: records.publishTime // 发布日期
            }
            this.$emit('handleBasicInfo', records)
          }
          this.basicData = basicData
        })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "~@/assets/styles/frontPage/page/materials.scss";
</style>
